﻿@inject IStringLocalizer<CheckboxListNormal> Localizer

<CheckboxList TValue="string" @bind-Value="@Value1" Items="@Items" ShowLabel="true" DisplayText="@Localizer[nameof(Foo.Name)]" OnSelectedChanged="@OnSelectedChanged" />
<BlockLogger class="mt-3" @ref="Trace" />

@code {
    private string Value1 { get; set; } = "1,3";

    private BlockLogger? Trace { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items { get; set; } = new List<SelectedItem>(new List<SelectedItem>
    {
        new SelectedItem { Text = "Item 1", Value = "1" },
        new SelectedItem { Text = "Item 2", Value = "2" , IsDisabled = true },
        new SelectedItem { Text = "Item 3", Value = "3" },
        new SelectedItem { Text = "Item 4", Value = "4" },
    });

    private Task OnSelectedChanged(IEnumerable<SelectedItem> items, string value)
    {
        Trace?.Log($"{Localizer["Header"]} {items.Count(i => i.Active)} {Localizer["Counter"]}：{value}");
        return Task.CompletedTask;
    }
}
